//
//  PayMoneyDetailZuiXinViewController.m
//  PropertyManager
//
//  Created by 楠 on 2018/10/21.
//  Copyright © 2018年 Tng. All rights reserved.
//

#import "PayMoneyDetailZuiXinViewController.h"

@interface PayMoneyDetailZuiXinViewController () <UITableViewDelegate,UITableViewDataSource>

@property (nonatomic,strong) UITableView * tableview;

@end

@implementation PayMoneyDetailZuiXinViewController

static NSString * PayLatestDetailTableViewCellID = @"PayLatestDetailTableViewCell";
static NSString * PaymoneyTitleTableViewCellID = @"PaymoneyTitleTableViewCell";

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"缴费账单详情";
    [self creatTableview];
    [self registCell];
}

#pragma mark -微信回调
-(void)weiXinPayDidBack:(NSNotification *)notice
{
    NSDictionary * dic = notice.userInfo;
    NSString * code = dic[@"code"];
    WeakSelf;
    if ([code isEqualToString:@"0"]) {
        UIAlertController * alert = [UIAlertController alertControllerWithTitle:@"支付成功" message:@"" preferredStyle:UIAlertControllerStyleAlert];
        UIAlertAction * action1 = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            ElectronTicketViewController * ctr =[[ElectronTicketViewController alloc] init];
            [weakSelf.navigationController pushViewController:ctr animated:YES];
        }];
        [alert addAction: action1];
        [self presentViewController:alert animated:YES completion:nil];
    }else
    {
        UIAlertController * alert = [UIAlertController alertControllerWithTitle:@"支付失败" message:@"" preferredStyle:UIAlertControllerStyleAlert];
        UIAlertAction * action1 = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            [weakSelf.navigationController popViewControllerAnimated:YES];
        }];
        [alert addAction: action1];
        [self presentViewController:alert animated:YES completion:nil];
    }
}

#pragma mark - 支付宝回调
-(void)AliPayDidBack:(NSNotification *)notice
{
    NSDictionary * dic = notice.userInfo;
    NSString * str =dic[@"resultStatus"];
    NSString * payMessage  = @"支付失败";
    if ([str isEqualToString:@"6001"]) {
        payMessage  = @"支付失败";
    }else if([str isEqualToString:@"6002"])
    {
        payMessage  = @"网络延迟,请稍后再试";
    }else if([str isEqualToString:@"9000"])
    {
        payMessage  = @"支付成功";
    }else
    {
        payMessage  = @"交易延迟,请稍后再试";
    }
    WeakSelf;
    UIAlertController * alert = [UIAlertController alertControllerWithTitle:payMessage message:@"" preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction * action1 = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        if ([payMessage isEqualToString:@"支付成功"]) {
            ElectronTicketViewController * ctr =[[ElectronTicketViewController alloc] init];
            [weakSelf.navigationController pushViewController:ctr animated:YES];
        }
    }];
    [alert addAction: action1];
    [weakSelf presentViewController:alert animated:YES completion:nil];
}
-(void)registCell
{
    [self.tableview registerClass:[PayLatestDetailTableViewCell class] forCellReuseIdentifier:PayLatestDetailTableViewCellID];
    [self.tableview registerClass:[PaymoneyTitleTableViewCell class] forCellReuseIdentifier:PaymoneyTitleTableViewCellID];
}

-(void)creatTableview{
    if (self.tableview == nil) {
        UITableView * tableview;
        if (self.isPay) {
            tableview = [[UITableView alloc] initWithFrame:CGRectMake(0, kStatusAndNavBarH, WIDTH, HEIGHT - kStatusAndNavBarH - kHomeLineH - 50) style:UITableViewStyleGrouped];
        }else
        {
            tableview = [[UITableView alloc] initWithFrame:CGRectMake(0, kStatusAndNavBarH, WIDTH, HEIGHT - kStatusAndNavBarH - kHomeLineH) style:UITableViewStyleGrouped];
        }
        tableview.delegate = self;
        tableview.dataSource = self;
        tableview.separatorStyle = UITableViewCellSeparatorStyleNone;
        if (@available(iOS 11.0, *)) {
            tableview.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentAutomatic;
        }
        self.tableview = tableview;
        [self.view addSubview:self.tableview];
    }
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 6;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {
        return 115;
    }
    if(indexPath.row == 0)
    {
        return 217;
    }else if (indexPath.row == 5)
    {
        return 93;
    }
    return 32;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 6;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {
        PaymoneyTitleTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:PaymoneyTitleTableViewCellID];
        [cell send];
        return cell;
    }
    //    if(indexPath.row == 0)
    //    {
    //        PayLatestMoneyTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:PayLatestMoneyTableViewCellID];
    //
    //        return cell;
    //    }else if (indexPath.row == 5)
    //    {
    //        PayLatestNullTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:PayLatestNullTableViewCellID];
    //        return cell;
    //    }else
    //    {
    PayLatestDetailTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:PayLatestDetailTableViewCellID];
    //        if (indexPath.row == 1) {
    //            cell.titleLabel.text = @"记账周期";
    //            cell.detailLabel.text = self.detailOverDueModel.fareperiod;
    //        }else if (indexPath.row == 2)
    //        {
    //            cell.titleLabel.text = @"出账日";
    //            cell.detailLabel.text = self.detailOverDueModel.busreceivemonth;
    //        }else if (indexPath.row == 3)
    //        {
    //            cell.titleLabel.text = @"合同编号";
    //            cell.detailLabel.text = self.detailOverDueModel.pkPact;
    //        }else
    //        {
    //            cell.titleLabel.text = @"缴费状态";
    //            cell.detailLabel.text = @"已逾期";
    //        }
    return cell;
    //    }
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}

-(BOOL)hidesBottomBarWhenPushed
{
    return YES;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
